/** 后台-配置列表页面 **/
import Http from '@/common/js/http.js'
import Pagekey from './page_form/pagekey.js'
import Datas from './page_form/data.js'
import EduMessage from '@/common/js/message.js';

export default {
  namespaced: true,
  state: {
    responseData: null
  },
  modules: {
    pagekey: Pagekey,
    datas: Datas
  },
  mutations: {
    SET_RESPONSE_DATA: (state, data) => {
      state.responseData = data
    }
  },
  actions: {
    page({
      commit,
      dispatch
    }, {
      uri,
      params
    }) {
      dispatch('setLoading', true, {
        root: true
      })
      // 设置表单key
      dispatch('pagekey/setPagekeyList', [])
      Http.get(uri, params, res => {
        // 返回数据绑定
        commit('SET_RESPONSE_DATA', res.data)
        // 设置表单key
        dispatch('pagekey/setPagekeyList', res.data.pageKey)
        // 设置表单数据
        dispatch('datas/setDatas', res.data.datas);
        dispatch('setLoading', false, {
          root: true
        });
      }, error => {
        EduMessage.error(error.msg);
      }, false)
    }
  },
  getters: {
    // 返回数据
    response(state) {
      return state.responseData
    }
  }
}
